import 'uni-js-bridge'
import { HeaderProps, CBInterface, ToUniCb, CallbackParams } from "@/utils/hybrid/interface";

if (!window.UniJsBridge) {
    throw new Error('window.UniJsBridge 不存在')
}

const UniJsBridge = window.UniJsBridge

export class WebviewJavascriptBridge {
    uni = UniJsBridge.uni

    setHeader(data?: HeaderProps, callback?: CBInterface) {
        UniJsBridge.callHandler('setHeader', data, (res: CallbackParams, cb: ToUniCb) => {
            callback && callback(res, cb)
        })
    }

    login(params: any, callback?: CBInterface) {
        UniJsBridge.callHandler('login', params, (res: CallbackParams, cb: ToUniCb) => {
            callback && callback(res, cb)
        })
    }

    logout(params: any, callback?: CBInterface) {
        UniJsBridge.callHandler('logout', params, (res: CallbackParams, cb: ToUniCb) => {
            callback && callback(res, cb)
        })
    }
}

export default new WebviewJavascriptBridge()
